﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageProtocol
{
    public class MessageConstants
    {
        public const uint TYPE_REQUEST_PING = 0x00;
        public const uint TYPE_REQUEST_ECHO = 0x01;
        public const uint TYPE_REQUEST_SAVE = 0x02;
        public const uint TYPE_REQUEST_GET = 0x03;

        public const byte NOT_LASTMSG = 0x00;
        public const byte LASTMSG = 0x01;
    }

    public interface ISerializable
    {
        byte[] GetBytes();
        int GetSize();
    }

    public class Message : ISerializable
    {
        public Header header{ get; set;}
        public ISerializable Body { get; set; }

        public byte[] GetBytes()
        {
            byte[] bytes = new byte[GetSize()];

            header.GetBytes().CopyTo(bytes, 0);
            Body.GetBytes().CopyTo(bytes, header.GetSize());

            return bytes;
        }
        public int GetSize()
        {
            return header.GetSize() + Body.GetSize();
        }
    }

}
